// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Aggregations;

public sealed partial class NestedAggregation
{
	/// <summary>
	/// <para>The path to the field of type `nested`.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("path")]
	public Elastic.Clients.Elasticsearch.Field? Path { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Aggregations.Aggregation(NestedAggregation nestedAggregation) => Elastic.Clients.Elasticsearch.Aggregations.Aggregation.Nested(nestedAggregation);
}

public sealed partial class NestedAggregationDescriptor<TDocument> : SerializableDescriptor<NestedAggregationDescriptor<TDocument>>
{
	internal NestedAggregationDescriptor(Action<NestedAggregationDescriptor<TDocument>> configure) => configure.Invoke(this);

	public NestedAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Field? PathValue { get; set; }

	/// <summary>
	/// <para>The path to the field of type `nested`.</para>
	/// </summary>
	public NestedAggregationDescriptor<TDocument> Path(Elastic.Clients.Elasticsearch.Field? path)
	{
		PathValue = path;
		return Self;
	}

	/// <summary>
	/// <para>The path to the field of type `nested`.</para>
	/// </summary>
	public NestedAggregationDescriptor<TDocument> Path<TValue>(Expression<Func<TDocument, TValue>> path)
	{
		PathValue = path;
		return Self;
	}

	/// <summary>
	/// <para>The path to the field of type `nested`.</para>
	/// </summary>
	public NestedAggregationDescriptor<TDocument> Path(Expression<Func<TDocument, object>> path)
	{
		PathValue = path;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (PathValue is not null)
		{
			writer.WritePropertyName("path");
			JsonSerializer.Serialize(writer, PathValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class NestedAggregationDescriptor : SerializableDescriptor<NestedAggregationDescriptor>
{
	internal NestedAggregationDescriptor(Action<NestedAggregationDescriptor> configure) => configure.Invoke(this);

	public NestedAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Field? PathValue { get; set; }

	/// <summary>
	/// <para>The path to the field of type `nested`.</para>
	/// </summary>
	public NestedAggregationDescriptor Path(Elastic.Clients.Elasticsearch.Field? path)
	{
		PathValue = path;
		return Self;
	}

	/// <summary>
	/// <para>The path to the field of type `nested`.</para>
	/// </summary>
	public NestedAggregationDescriptor Path<TDocument, TValue>(Expression<Func<TDocument, TValue>> path)
	{
		PathValue = path;
		return Self;
	}

	/// <summary>
	/// <para>The path to the field of type `nested`.</para>
	/// </summary>
	public NestedAggregationDescriptor Path<TDocument>(Expression<Func<TDocument, object>> path)
	{
		PathValue = path;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (PathValue is not null)
		{
			writer.WritePropertyName("path");
			JsonSerializer.Serialize(writer, PathValue, options);
		}

		writer.WriteEndObject();
	}
}